/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sicav.dao;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.sicav.entidades.Tempresa;

/**
 *
 * @author walter
 */
@Stateless
public class empresaDAO {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
@PersistenceContext(unitName = "SicavPU")
    private EntityManager em;
   
    public void persist(Object object) {
        try {
        em.persist(object);    
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();            
        }                    
    }
   
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    public List<Tempresa> getnomEmpresa(Tempresa empresa){
        List<Tempresa> lista = null;     //new ArrayList<Address>();
        Query q = em.createNamedQuery("Tempresa.findByCnomEmpresa");
        q.setParameter("cnomEmpresa", "%".concat(empresa.getCnomEmpresa()).concat("%"));
        lista = q.getResultList();
        return lista;
    }    
    public boolean modificaAddress(Tempresa empresa){
        try {
            em.merge(empresa);
            return true;
        } catch (Exception e) {
            return false;
        }
    }    
    /*public boolean eliminaAddress(Address address){
        try {
            Address adr = em.find(Address.class, address.getIdAdr());
            em.remove(adr);
            return true;
        } catch (Exception e) {
            return false;
        }
    }*/
}
